//package com.example.dialog.Activity;
//
//import android.content.Intent;
//import android.os.Bundle;
//import android.view.View;
//import android.widget.Button;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.example.dialog.R;
//import com.example.dialog.Tools.MyImageView;
//
//public class ArticleDetailsActivity extends AppCompatActivity {
//    private ImageView iv_back;
//    private MyImageView iv_usrPortrait;
//    private TextView tv_usrName;
//    private TextView tv_title;
//    private Button btn_follow;
//    private TextView tv_data_read;
//    private TextView tv_mainBody;
//    private ImageView iv_liked;
//    private TextView tv_likes_cnt;
//    private ImageView iv_stared;
//    private TextView tv_stars_cnt;
//    private ImageView iv_commented;
//    private Intent intent;
//
//    protected void onCreate(Bundle savedInstanceState) {
//
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_article_details);
//
//        this.iv_back = findViewById(R.id.iv_back);
//        this.iv_usrPortrait = findViewById(R.id.iv_usrPortrait); //头像
//        this.tv_usrName = findViewById(R.id.tv_usrName);        //用户名
//        this.tv_title = findViewById(R.id.tv_title);            //文章标题
//        this.btn_follow = findViewById(R.id.btn_follow);        //关注按钮
//        this.tv_data_read = findViewById(R.id.tv_data_read);    //阅读量
//        this.tv_mainBody = findViewById(R.id.tv_mainBody);      //正文
//
//        this.iv_liked = findViewById(R.id.iv_liked); //点赞
//        this.tv_likes_cnt = findViewById(R.id.tv_likes_cnt); //点赞
//        this.iv_stared = findViewById(R.id.iv_stared); //收藏
//        this.tv_stars_cnt = findViewById(R.id.tv_stars_cnt); //收藏
//        this.iv_commented = findViewById(R.id.iv_commented); //评论
//        this.intent = getIntent();
//
//
//        iv_back.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                finish();
//                //overridePendingTransition(R.anim.slide_out_from_right, R.anim.slide_in_from_left);
//            }
//        });
//
//        set_relevant_data();
//        init_ClickListener();
//    }
//    private void set_relevant_data() {
//        iv_usrPortrait.setImageURL(intent.getStringExtra("usrImage"));
//        tv_usrName.setText(intent.getStringExtra("mtv_author"));
//        tv_title.setText(intent.getStringExtra("mtv_title"));
//        tv_data_read.setText(intent.getStringExtra("mtv_data_read") + "人阅读");
//        tv_mainBody.setText(intent.getStringExtra("mtv_summary"));  // 正文内容
//        //intent.getStringExtra("mtv_summary")
//
//        // 确保点赞数和收藏数正确设置
//        tv_likes_cnt.setText(intent.getStringExtra("mtv_data_like"));
//        tv_stars_cnt.setText(intent.getStringExtra("mtv_data_star"));
//    }
//
//    private void init_ClickListener(){
//        iv_liked.setOnClickListener(new View.OnClickListener() {    //点赞
//            boolean flag = false;
//            @Override
//            public void onClick(View view) {
//                int cnt = Integer.parseInt(tv_likes_cnt.getText().toString());
//                if(!flag){ //点赞
//                    iv_liked.setImageResource(R.drawable.liked);
//
//                    tv_likes_cnt.setText(String.valueOf(cnt + 1));
//                    flag = true;
//                }
//                else{
//                    iv_liked.setImageResource(R.drawable.not_liked);
//                    tv_likes_cnt.setText(String.valueOf(cnt - 1));
//                    flag = false;
//                }
//            }
//        });
//
//        iv_stared.setOnClickListener(new View.OnClickListener() {
//            boolean flag = false;
//            @Override
//            public void onClick(View view) {
//                int cnt = Integer.parseInt(tv_stars_cnt.getText().toString());
//                if(!flag){ //点赞
//                    iv_stared.setImageResource(R.drawable.stared);
//
//                    tv_stars_cnt.setText(String.valueOf(cnt + 1));
//                    flag = true;
//                }
//                else{
//                    iv_stared.setImageResource(R.drawable.not_stared);
//                    tv_stars_cnt.setText(String.valueOf(cnt - 1));
//                    flag = false;
//                }
//            }
//        });
//
//        btn_follow.setOnClickListener(new View.OnClickListener() {
//            boolean flag = false;
//            @Override
//            public void onClick(View view) {
//                if(!flag){
//                    btn_follow.setText("关注");
//                    flag = true;
//                }
//                else{
//                    btn_follow.setText("已关注");
//                    flag = false;
//                }
//            }
//        });
//    }
//}


//here

package com.example.dialog.Activity;

import static java.security.AccessController.getContext;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.dialog.R;
import com.example.dialog.Tools.MyImageView;

public class ArticleDetailsActivity extends AppCompatActivity {
    private ImageView iv_back;
    private MyImageView iv_usrPortrait;
    private TextView tv_usrName;
    private TextView tv_title;
    private Button btn_follow;
    private TextView tv_data_read;
    private MyImageView iv_contentImage;
    private TextView tv_mainBody;
    private ImageView iv_liked;
    private TextView tv_likes_cnt;
    private ImageView iv_stared;
    private TextView tv_stars_cnt;
    private ImageView iv_commented;
    private Intent intent;

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article_details);

        this.iv_back = findViewById(R.id.iv_back);
        this.iv_usrPortrait = findViewById(R.id.iv_usrPortrait); //头像
        this.tv_usrName = findViewById(R.id.tv_usrName);        //用户名
        this.tv_title = findViewById(R.id.tv_title);            //文章标题
        this.btn_follow = findViewById(R.id.btn_follow);        //关注按钮
        this.tv_data_read = findViewById(R.id.tv_data_read);    //阅读量
        this.iv_contentImage = findViewById(R.id.iv_contentImage); //正文图
        this.tv_mainBody = findViewById(R.id.tv_mainBody);      //正文

        this.iv_liked = findViewById(R.id.iv_liked); //点赞
        this.tv_likes_cnt = findViewById(R.id.tv_likes_cnt); //点赞
        this.iv_stared = findViewById(R.id.iv_stared); //收藏
        this.tv_stars_cnt = findViewById(R.id.tv_stars_cnt); //收藏
        this.iv_commented = findViewById(R.id.iv_commented); //评论
        this.intent = getIntent();


        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                //overridePendingTransition(R.anim.slide_out_from_right, R.anim.slide_in_from_left);
            }
        });

        set_relevant_data();
        init_ClickListener();
    }
    private void set_relevant_data(){

        iv_usrPortrait.setImageURL(intent.getStringExtra("usrImage"));
        tv_usrName.setText(intent.getStringExtra("mtv_author"));
        tv_title.setText(intent.getStringExtra("mtv_title"));
        tv_data_read.setText(intent.getStringExtra("mtv_data_read") + "人阅读");

        iv_contentImage.setImageURL(intent.getStringExtra("contentImage"));
        tv_mainBody.setText(intent.getStringExtra("mtv_content"));

        tv_likes_cnt.setText(intent.getStringExtra("mtv_data_like"));
        tv_stars_cnt.setText(intent.getStringExtra("mtv_data_star"));

    }
    private void init_ClickListener(){
        iv_liked.setOnClickListener(new View.OnClickListener() {    //点赞
            boolean flag = false;
            @Override
            public void onClick(View view) {

                int cnt = Integer.parseInt(tv_likes_cnt.getText().toString());
                if(!flag){ //点赞
                    iv_liked.setImageResource(R.drawable.liked);

                    tv_likes_cnt.setText(String.valueOf(cnt + 1));
                    flag = true;
                }
                else{
                    iv_liked.setImageResource(R.drawable.not_liked);
                    tv_likes_cnt.setText(String.valueOf(cnt - 1));
                    flag = false;
                }
            }
        });

        iv_stared.setOnClickListener(new View.OnClickListener() {
            boolean flag = false;
            @Override
            public void onClick(View view) {
                int cnt = Integer.parseInt(tv_stars_cnt.getText().toString());
                if(!flag){ //点赞
                    iv_stared.setImageResource(R.drawable.stared);

                    tv_stars_cnt.setText(String.valueOf(cnt + 1));
                    flag = true;
                }
                else{
                    iv_stared.setImageResource(R.drawable.not_stared);
                    tv_stars_cnt.setText(String.valueOf(cnt - 1));
                    flag = false;
                }
            }
        });

        btn_follow.setOnClickListener(new View.OnClickListener() {
            boolean flag = false;
            @Override
            public void onClick(View view) {
                if(!flag){
                    btn_follow.setText("关注");
                    flag = true;
                }
                else{
                    btn_follow.setText("已关注");
                    flag = false;
                }
            }
        });
    }
}

